#ifndef ZLH_ARRAY2D_H
#define ZLH_ARRAY2D_H

template<class T>
class Array2D {
public:

    Array2D(size_t w, size_t h) {
        mWidth = w;
        mHeight = h;
        mData = new T[w * h];
    }

    ~Array2D(void) {
        delete[] mData;
    }

    inline size_t getWidth() {
        return mWidth;
    }

    inline size_t getHeight() {
        return mHeight;
    }

    inline T getVal(size_t x, size_t y) {
        if (!(x < mWidth))
            x = mWidth - 1;
        if (!(y < mHeight))
            y = mHeight - 1;
        return mData[y * mWidth + x];
    }

    inline T& getRef(size_t x, size_t y) {
        if (!(x < mWidth))
            x = mWidth - 1;
        if (!(y < mHeight))
            y = mHeight - 1;
        return mData[y * mWidth + x];
    }

    inline T* getPtr(size_t x, size_t y) {
        if (!(x < mWidth))
            x = mWidth - 1;
        if (!(y < mHeight))
            y = mHeight - 1;
        return &mData[y * mWidth + x];
    }
protected:
    T* mData;
    size_t mWidth;
    size_t mHeight;
};

